import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/cooperation_page_activity.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/cooperation_controller/cooperation_page_controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/utils/color_util.dart';

class CooperationPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '邀请好友',
        showLeading: false,
        backgroundColor: pageBgColor,
      ),
      body: ScrollConfigurationCommon(child: ListView(
        children: [
          Stack(
            children: [
              Container(
                width: 375.w,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Image.asset(
                      'assets/images/cooperation_bg.png',
                      width: 375.w,
                      height: 240.w,
                      fit: BoxFit.cover,
                    ),
                    SizedBox(height: 86.h)
                  ],
                ),
              ),
              Positioned(
                left: 0,
                bottom: 0,
                child: _invitationMsg()
              )
            ],
          ),
          GetBuilder<CooperationPageController>(
            init: CooperationPageController(),
            builder: (controller) {
              return CooperationPageActivity(cooperationPageController: controller);
            },
          )
          // BarUtil(title: '邀请好友'),
          // Container(
          //   padding: EdgeInsets.symmetric(horizontal: 16.w),
          //   child: Container(
          //     decoration: BoxDecoration(
          //       borderRadius: BorderRadius.circular(5.w),
          //       color: bgWhiteColor
          //     ),
          //     child: Row(
          //       children: [
          //         GetBuilder<CooperationPageController>(
          //           init: CooperationPageController(),
          //           builder: (controller) {
          //             return _extensionItem(
          //               path: 'assets/icons/icon_invitation.png', 
          //               title: '邀请码加入', 
          //               onTap: () {
          //                 Get.dialog(StatefulBuilder(
          //                   builder: (context, setButtomSheetState) {
          //                     return InputDialogUtil(
          //                       title: '邀请码加入',
          //                       hintText: '请输入邀请码',
          //                       defaultValue: controller.invitationCode.value,
          //                       onChenge: (value) {
          //                         controller.invitationCode.value = value;
          //                       },
          //                       onSubmit: () {
          //                         controller.invitations();
          //                       }
          //                     );
          //                   }
          //                 ));
          //               }
          //             );
          //           },
          //         ),
          //         GetBuilder<CommonPageController>(
          //           builder: (controller) {
          //             return _extensionItem(
          //               path: 'assets/icons/icon_link.png', 
          //               title: '推广链接', 
          //               showBorder: false,
          //               onTap: () {
          //                 if (!TextUtil.isEmpty(controller.userData.value.invitationUrl)) {
          //                   Clipboard.setData(ClipboardData(text: controller.userData.value.invitationUrl));
          //                   EasyLoading.showToast('复制成功');
          //                 }
          //               }
          //             );
          //           },
          //         )
          //       ],
          //     ),
          //   ),
          // )
        ],
      )),
    );
  }

  /// 邀请信息
  Widget _invitationMsg() {
    return Container(
      width: 375.w,
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(5.w),
          color: bgWhiteColor
        ),
        child: GetBuilder<CommonPageController>(
          builder: (controller) {
            return Column(
              children: [
                _invitationItem('邀请码', '${controller.userData.value.invitationCode}', '复制邀请码'),
                _invitationItem('邀请链接', '${controller.userData.value.invitationUrl}', '复制邀请链接'),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 49.w),
                  height: 65.h,
                  child: Center(
                    child: ButtonUtil(
                      text: '海报邀请', 
                      fontSize: 14.sp, 
                      borderRadius: 18.w, 
                      height: 36.h, 
                      onTop: () {
                        Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.INVITATION_POSTER_PAGE}');
                      }
                    ),
                  ),
                )
              ],
            );
          },
        ),
      ),
    );
  }

  /// 邀请码、邀请链接
  Widget _invitationItem(String title, String value, String copyStr) {
    return Container(
      height: 43.h,
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: Row(
        children: [
          Container(
            width: 64.w,
            child: Text(
              title,
              style: TextStyle(
                color: textSubtitleColor,
                fontSize: 14.sp
              ),
            ),
          ),
          Expanded(child: Container(
            padding: EdgeInsets.symmetric(horizontal: 6.w),
            child: Text(
              value,
              textAlign: TextAlign.end,
              overflow: TextOverflow.ellipsis,
              maxLines: 1,
              style: TextStyle(
                color: textBlackColor,
                fontSize: 16.sp
              ),
            ),
          )),
          SizedBox(width: 12.w),
          // InkWellUtil.shakeProofInkWell(Image.asset(
          //   'assets/icons/icon_copy.png',
          //   width: 14.w,
          //   height: 14.w,
          // ), () {
          //   if (!TextUtil.isEmpty(value)) {
          //     Clipboard.setData(ClipboardData(text: value));
          //     EasyLoading.showToast('复制成功');
          //   }
          // })
          InkWellUtil.shakeProofInkWell(Text(
            copyStr,
            style: TextStyle(
              color: mainTextColor,
              fontSize: 12.sp
            ),
          ), () {
            if (!TextUtil.isEmpty(value)) {
              Clipboard.setData(ClipboardData(text: value));
              EasyLoading.showToast('复制成功');
            }
          })
        ],
      ),
    );
  }

  // /// 邀请好友Item
  // Widget _extensionItem({required String path, required String title, required Function onTap, bool showBorder = true}) {
  //   return InkWellUtil.shakeProofInkWell(Container(
  //     padding: EdgeInsets.symmetric(vertical: 12.h),
  //     width: 171.w,
  //     alignment: Alignment.center,
  //     decoration: BoxDecoration(
  //       border: Border(
  //         right: showBorder ? BorderSide(
  //           width: 1.w,
  //           color: lineColor
  //         ) : BorderSide.none
  //       )
  //     ),
  //     child: Column(
  //       children: [
  //         Image.asset(
  //           path,
  //           width: 48.w,
  //           height: 48.w,
  //         ),
  //         SizedBox(height: 4.h),
  //         Text(
  //           title,
  //           style: TextStyle(
  //             color: textBlackColor,
  //             fontSize: 12.sp
  //           ),
  //         )
  //       ],
  //     ),
  //   ), () => onTap());
  // }

}